<template>
	<view class="content">
		<!-- 自定义导航栏 -->

	</view>
</template>

<script>
	import {
		storage
	} from "@/common/storage.js";
	import {
		apis
	} from "@/api/api";
	export default {
		name: 'launch',
		data() {
			return {

			};
		},
		onLoad() {
			uni.showLoading({
				title: "启动中",
			});
			var userInfoModel = storage.getStorageDataSync("userInfo");
			this.smartLoginData(userInfoModel.userLoginName)
		},
		methods: {
			smartLoginData(userLoginName) {
				console.log("===数字杰能传递过来的账号密码====", userLoginName);
				storage.setStorageDataSync("token", "");
				var that = this
				apis.smartLockLogin({
					username: userLoginName
				}).then(result => {
					if (result.res.data.code == '200') {
						storage.setStorageDataSync('token', result.res.data.token);
						that.getUserInfoData()
					} else {
						that.$show.toastMessage(result.res.data.msg);
					}
				})
			},
			getUserInfoData() {
				var that = this
				apis.getUserInfo().then(result => {
					if (result.res.data.code == '200') {
						storage.setStorageDataSync("sUserInfo", result.res.data.data.user);
						storage.setStorageDataSync("sPermissions", result.res.data.data.permissions);
						uni.hideLoading()
						uni.switchTab({
							url: '/pages/smartLock/views/index'
						})
					} else {
						that.$show.toastMessage(result.res.data.msg);
					}
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.content {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background-color: #fff;
	}
</style>